package com.ruoyi.web.controller.business;

import java.util.List;

import com.ruoyi.business.domain.*;
import com.ruoyi.business.service.IBusContractService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.service.IBusContractDeliveryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 合同交货Controller
 * 
 * @author ruoyi
 * @date 2021-09-02
 */
@RestController
@RequestMapping("/business/delivery")
public class BusContractDeliveryController extends BaseController
{
    @Autowired
    private IBusContractDeliveryService busContractDeliveryService;

    @Autowired
    private IBusContractService busContractService;

    /**
     * 查询合同交货列表
     */
   // @PreAuthorize("@ss.hasPermi('business:delivery:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusContractDelivery busContractDelivery)
    {
        startPage();
        List<BusContractDelivery> list = busContractDeliveryService.selectBusContractDeliveryList(busContractDelivery);
        return getDataTable(list);
    }

    /**
     * 查询合同交货列表(index 页面接口)
     */
    //@PreAuthorize("@ss.hasPermi('business:delivery:listContractDelivery')")
    @GetMapping("/listContractDelivery")
    public TableDataInfo listContractDelivery(BusContractDeliveryParam busContractDeliveryParam)
    {
        startPage();
        List<BusContractDeliveryDetail> list = busContractDeliveryService.getContractDeliveryList(busContractDeliveryParam);
        return getDataTable(list);
    }

    /**
     * 导出合同交货列表
     */
    //@PreAuthorize("@ss.hasPermi('business:delivery:export')")
    @Log(title = "合同交货", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BusContractDelivery busContractDelivery)
    {
        BusContract busContract = busContractService.selectBusContractByContractId(busContractDelivery.getContractId());
        List<BusContractDelivery> list = busContractDeliveryService.selectBusContractDeliveryList(busContractDelivery);
        ExcelUtil<BusContractDelivery> util = new ExcelUtil<BusContractDelivery>(BusContractDelivery.class);
        return util.exportExcel(list, "合同编号【"+busContract.getContractNo()+"】交货信息");
    }

    /**
     * 获取合同交货详细信息
     */
    //@PreAuthorize("@ss.hasPermi('business:delivery:query')")
    @GetMapping(value = "/{deliveryId}")
    public AjaxResult getInfo(@PathVariable("deliveryId") Long deliveryId)
    {
        return AjaxResult.success(busContractDeliveryService.selectBusContractDeliveryByDeliveryId(deliveryId));
    }

    /**
     * 新增合同交货
     */
   // @PreAuthorize("@ss.hasPermi('business:delivery:add')")
    @Log(title = "合同交货", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusContractDelivery busContractDelivery)
    {
        busContractDelivery.setCreateBy(getUsername());
        return toAjax(busContractDeliveryService.insertBusContractDelivery(busContractDelivery));
    }

    /**
     * 修改合同交货
     */
   // @PreAuthorize("@ss.hasPermi('business:delivery:edit')")
    @Log(title = "合同交货", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusContractDelivery busContractDelivery)
    {
        busContractDelivery.setUpdateBy(getUsername());
        return toAjax(busContractDeliveryService.updateBusContractDelivery(busContractDelivery));
    }

    /**
     * 删除合同交货
     */
    //@PreAuthorize("@ss.hasPermi('business:delivery:remove')")
    @Log(title = "合同交货", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deliveryIds}")
    public AjaxResult remove(@PathVariable Long[] deliveryIds)
    {
        return toAjax(busContractDeliveryService.deleteBusContractDeliveryByDeliveryIds(deliveryIds));
    }
}
